package com.xjrsoft.common.utils;

import cn.hutool.core.lang.TypeReference;
import cn.hutool.extra.spring.SpringUtil;
import com.xjrsoft.common.constant.GlobalConstant;
import com.xjrsoft.module.organization.entity.UserRoleRelation;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author hnyyzy
 * @version 1.0
 * @date 2024/8/2 13:57
 */
public class CommonUtil {

    private static final RedisUtil redisUtil;

    static {
        redisUtil = SpringUtil.getBean(RedisUtil.class);
    }

    /**
     * 获取所有的admin用户
     * @return
     */
    public static List<Long> getAllAdminUserIdList(){
        List<UserRoleRelation> userRoleRelations = redisUtil.get(GlobalConstant.USER_ROLE_RELATION_CACHE_KEY, new TypeReference<List<UserRoleRelation>>() {
        });
        //获取超级管理员成员
        List<Long> adminUserIds = userRoleRelations.stream().filter(x -> x.getRoleId().equals(GlobalConstant.SUPER_ADMIN_ROLE_ID)).map(UserRoleRelation::getUserId).collect(Collectors.toList());
        return adminUserIds;
    }
}
